<html>
<head>
    <meta charset="utf-8">
    <title>流程抄送转发</title>
    <#include "/pubHeadStyle.html">
</head>
<body>
<div id="processCopyToDiv">
    <!--数据列表-->
    <div class="tablesize roles" style="position: absolute;top:0;right:0px;bottom: 0;left: 0px;padding: 10px">
        <table class="layui-table"  lay-filter="processCopyTo" id="processCopyTo" style="text-align: center;"></table>
    </div>
</div>
<!--查询表单-->
<script type="text/html" id="headerToolsBar">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-sm" lay-event="query">
            <i class="layui-icon layui-icon-search"></i>
            <span>查询</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="reload">
            <i class="layui-icon layui-icon-refresh"></i>
            <span>重置</span>
        </a>

        <!--TODO 按钮样式修改↓，暂为盾牌加对勾，老平台为一颗眼睛,MyList.html页面同理-->

        <a class="layui-btn layui-btn-sm" lay-event="mark">
            <i class="layui-icon layui-icon-auz"></i>
            <span>标记为已读</span>
        </a>
        <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">
            <i class="layui-icon layui-icon-delete"></i>
            <span>删除</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="reset" href="${ctx}/workflow/processRun/view/history" >
            <i class="layui-icon layui-icon-return"></i>
            <span>返回</span>
        </a>
    </div>
    <form class="layui-form" action="" lay-filter="processCopyToQueryForm" style="margin-top:10px">
        <div class="table-top-filter">
            <div class="table-filter-alone">
                <label class="layui-form-label">流程标题:</label>
                <input type="text" name="Q_subject_SL" id="subject" class="layui-input filter-value" placeholder="流程标题"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">接受人:</label>
                <input type="text" name="Q_ccUName_SL" id="ccUName" class="layui-input filter-value"placeholder="接收人"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">发起人:</label>
                <input type="text" name="Q_creator_SL" id="creator" class="layui-input filter-value" placeholder="发起人"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">类型:</label>
                <select name="cpType" id="cpType" class="layui-input filter-value">
                    <option value="">全部</option>
                    <option value="1">抄送</option>
                    <option value="2">转发</option>
                </select>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">是否已读:</label>
                <select name="isRead" id="isRead" class="layui-input filter-value">
                    <option value="">全部</option>
                    <option value="1">已读</option>
                    <option value="0">未读</option>
                </select>
            </div>
        </div>
    </form>
</script>
<script type="text/html" id="manageBar">
    <!--管理-->
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delOne">删除</a>
</script>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','setter','table','form','util','commons','common','layer'], function(){
        var setter = layui.setter;
        var table = layui.table;
        var form = layui.form;
        var util = layui.util;
        var commons = layui.commons;
        var common = layui.common;
        var $ = layui.$;
        var layer = layui.layer;
        var tableH=commons.tabHeight();

        table.render({
            elem: '#processCopyTo'
            ,title:"抄送人"
            ,toolbar: '#headerToolsBar'
            ,method:"post"
            ,page: true
            ,height:tableH
            ,url:serverPath.workflowPath+setter.workflowLinkPath+"processCopyTo/list?runId=${runId}"
            ,cols: [[
                {type:'checkbox', align: 'center'}
                ,{field:'subject', title: '流程标题', align: 'center'}
                ,{field:'ccUName', title: '接受人', align: 'center'}
                ,{field:'creator', title: '发起人', align: 'center'}
                ,{field:'isRead', title: '是否已读', align: 'center',templet:function (d) {
                        if(d.isRead==0 || d.isRead=='0') {
                            return "<span style='color:red'>未读</span>";
                        }else if(d.isRead==1 || d.isRead=='1'){
                            return "<span style='color:green'>已读</span>";
                        }else{
                            return "";
                        }
                    }}
                ,{field:'ccTime', title: '阅读时间', align: 'center', templet:function (d) {
                        if(d.readTime== "undefined" || d.readTime=="" || d.readTime==null){
                            return "";
                        }
                        return util.toDateString(d.readTime, "yyyy-MM-dd HH:mm:ss");
                    }}
                ,{field:'cpType', title: '类型', align: 'center', templet:function (d) {
                        if(d.cpType==1 || d.cpType=='1') {
                            return "<span style='color:green'>抄送</span>";
                        }else if(d.cpType==2 || d.cpType=='2'){
                            return "<span style='color:brown'>转发</span>";
                        }else{
                            return "";
                        }
                    }}
                ,{field:'manage',title:"管理",toolbar:"#manageBar",align:"center"}
            ]]
        });

        //头部监听器
        table.on('toolbar(processCopyTo)', function (obj) {
            switch (obj.event) {
                case 'query':
                    //查询，不清除查询条件
                    reload(false);
                    break;
                case 'reload':
                    //重置，并清空查询条件
                    reload(true);
                    break;
                case 'mark':
                    //标记为已读，不清除查询条件
                    getCopyIds("mark");
                    break;
                case 'del':
                    //删除，不清除查询条件
                    getCopyIds("del");
                    break;
            }
        });
        table.on('tool(processCopyTo)', function(obj){
           if( obj.event=="delOne"){
               //直接删除，不清除查询条件
               markOrDel("del",obj.data.copyId);
           }
        });
        //表格重载
        function reload(isClear) {
            common.tableConditionRender("processCopyTo","processCopyToQueryForm",{where:{}},isClear);
        }
        //标记为已读或删除，获取数据
        function getCopyIds(urlStr) {
            var checkStatusData = table.checkStatus('processCopyTo').data;
            if(checkStatusData.length<=0){
                layer.msg("请至少选择一条有效数据",{icon:5,time:1000})
                return ;
            }
            var copyIds=[];
            for(var i=0;i<checkStatusData.length;i++){
                copyIds.push(checkStatusData[i].copyId);
            }
            //执行操作，不清除查询条件
            markOrDel(urlStr,copyIds.toString())
        }
        //标记为已读或删除，执行
        function markOrDel(urlStr,copyIds) {
            $.ajax({
                url:serverPath.workflowPath+setter.workflowLinkPath+"processCopyTo/"+urlStr
                ,method:'post'
                ,data:{copyIds:copyIds}
                ,dataType:'json'
                ,success:function (res) {
                    //刷新页面,按照已有查询条件刷新
                    if(commons._filterRecord(res)) {
                        layer.msg(res.msg, {icon: 6, time: 1000})
                        reload(false);
                    }else {
                        layer.msg(res.msg, {icon: 5, time: 1000})
                    }
                }
            })
        }
    });

</script>
<style>
    .layui-table-view .layui-form-checkbox[lay-skin=primary] i{
        margin-top: 4px;
    }
</style>
</body>
</html>